<?php
include( "admin/now5_header.php" );
$showType = intval( getvar( "showType" ) );
$gameArr = array( 29 => "五不中", 39 => "六不中", 40 => "七不中", 41 => "八不中", 42 => "九不中", 43 => "十不中", 44 => "十一不中", 45 => "十二不中" );
if ( !isset( $gameArr[$showType] ) )
{
    $showType = 29;
}
$sql = "select * from bet where bettype={$showType} and lotto_id={$lotto_id} and rame in (0,9) order by unitmoney desc, bettype, numbers";
$percent = 0;
$lostwin = array();
$showNumArr = array();
$showNumArr[$showType] = array();
$totalamount = array();
$totalamount[$showType] = 0;
$betcount = array();
$betcount[$showType] = 0;
$ary = array();
$ary[$showType] = array();
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $percent = $rs->f['upercent'];
    if ( 0 < $percent )
    {
        $percent /= 100;
    }
    $bettype = $rs->f['bettype'];
    $line_nums = $rs->f['line_nums'];
    $tmp = $percent * $rs->f['unitmoney'];
    $srcFlag = array_search( $line_nums, $showNumArr[$bettype] );
    if ( $srcFlag === false )
    {
        $ary[$bettype][] = array( "num" => $line_nums, "amount" => $tmp );
        $showNumArr[$bettype][] = $line_nums;
    }
    else
    {
        $ary[$bettype][$srcFlag] += "amount";
    }
    ++$betcount[$bettype];
    $totalamount[$bettype] ++;
    $rs->movenext();
}

$rs->close();
$sql = "select * from bet2 where lotto_id={$lotto_id} and bettype={$showType} and rame in (0,9) order by unitmoney desc, bettype, numbers";
$rs = getdb( $sql );

while ( !$rs->eof )
{
    $backs = $rs->f['back5'];
    $percent = $rs->f['percent255'] - 0;
    if ( 0 < $percent )
    {
        $percent /= 100;
    }
    $bettype = $rs->f['bettype'];
    $line_nums = $rs->f['line_nums'];
    $tmp = $rs->f['unitmoney'] * $percent;
    $srcFlag = array_search( $line_nums, $showNumArr[$bettype] );
	
    if ( $srcFlag == false )
    {
        
		$ary[$bettype][] = array( "num" => $line_nums, "amount" => $tmp );
        $showNumArr[$bettype][] = $line_nums;
		
	
    }
    else
    {
        
		$ary[$bettype][$srcFlag] += "amount";
    }
	
    ++$betcount[$bettype];
    $totalamount[$bettype] ++;
    $rs->movenext();
}

$rs->close();
$sql = "select * from bet8 where lotto_id={$lotto_id} and bettype={$showType} and rame in (0,9) order by amount desc, bettype, numbers";
$rs = getdb( $sql );
while ( !$rs->eof )
{
    $bettype = $rs->f['bettype'];
    $line_nums = $rs->f['line_nums'];
    $tmp = $rs->f['amount'];
    $srcFlag = array_search( $line_nums, $showNumArr[$bettype] );
    if ( $srcFlag === false )
    {
        $ary[$bettype][] = array( "num" => $line_nums, "amount" => 0 - $tmp );
        $showNumArr[$bettype][] = $line_nums;
    }
    else
    {
        $ary[$bettype][$srcFlag] -= "amount";
    }
    ++$betcount[$bettype];
    $totalamount -= $bettype;
    $rs->movenext();
}
$rs->close();
$list = array( "", "", "", "", "", "" );
$tot = 0;
if ( 0 < $betcount[$showType] )
{
    foreach ( $ary[$showType] as $lKey => $lVal )
    {
        $lostwin[$showType][$lKey] = 0 - $lVal['amount'];
    }
    asort( $lostwin[$showType] );
    reset( $lostwin[$showType] );
    $col = 1;
    $rn = 0;
    $ov = 0;
    foreach ( $lostwin[$showType] as $key => $val )
    {
        $c = $ary[$showType][$key]['num'];
        $n = intval( $ary[$showType][$key]['amount'] );
        if ( $c != "" )
        {
            if ( $col == 1 )
            {
                $list[0] .= $rn;
                $ov = 0;
            }
            $list[0] .= $rn;
            $list[0] .= $rn;
            $list[0] .= $rn;
            ++$tot;
            ++$col;
            if ( 20 < $col )
            {
                $list[0] .= $rn;
                $col = 1;
                $ov = 1;
                ++$rn;
            }
        }
    }
    if ( $ov == 0 )
    {
        $list[0] .= $rn;
    }
}

$disk = $disk == 0 ? 1 : $disk;
$rs = getdb( "select * from rate29 where lotto_id={$lotto_id} and disk={$disk} and bettype={$showType}" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>系统目前维护中，请稍後！</p>" );
    exit();
}
$rate_list = "";
$y = 0;
while ( $y <= 4 )
{
    $rate_list .= "<tr>";
    $x = 1;
    while ( $x <= 10 )
    {
        $num = d2( $y * 10 + $x );
        if ( $num == "50" )
        {
            break;
        }
        $rate = $rs->f["r".$num];
        $ball = "";
        if ( array_search( intval( $num ), $g_red_po ) !== false )
        {
            $ball = "background='image/red.gif'";
        }
        else if ( array_search( intval( $num ), $g_blue_po ) !== false )
        {
            $ball = "background='image/blue.gif'";
        }
        else
        {
            $ball = "background='image/green.gif'";
        }
        $rate_list .= "<td class='ball_td' align='middle' {$ball} bgColor='#c0d6eb' height='27' width='90'>"."<b>{$num}</b></td><td bgColor='#e7ebef' nowrap>"."&nbsp;<input type='button' onclick=ratediff({$showType},{$num},-0.01) value='-' class='btnmin'>&nbsp;"."{$rate}"."&nbsp;<input type='button' onclick=ratediff({$showType},{$num},0.01) value='+' class='btnplus'>&nbsp;"."</td>";
        ++$x;
    }
    $rate_list .= "</tr>";
    ++$y;
}
$tpl->set( "rate_list", $rate_list );
$i = 0;
while ( $i < 6 )
{
    $tpl->set( "list".$i, $list[$i] );
    ++$i;
}
$btn0 = getvar( "btn0" );
$btn1 = getvar( "btn1" );
if ( $btn0 == "" )
{
    $btn0 = 11;
}
if ( $btn1 == "" )
{
    $btn1 = 0.1;
}
$tpl->set( "btn0", $btn0 );
$tpl->set( "btn1", $btn1 );
$tpl->set( "totall", "显示排行前 <b>".$tot."</b> 笔，合计金额：<b>".$totalamount[$showType]."</b>" );
$tpl->load( "main", "now8.htm" );
$tpl->set( "jslang", $g_conf['language'] );
$tpl->set( "lotto_id", $lotto_id );
$tpl->set( "showTypeTitle", $gameArr[$showType] );
$tpl->set( "showType", $showType );
$tdListMenu = "";
foreach ( $gameArr as $key => $val )
{
    $urlTemp = "op.php?op=admin&fp=now8&showType={$key}&select={$selectid}";
    if ( $key == $showType )
    {
        $tdListMenu .= "<td class=td2>{$val}</td>";
    }
    else
    {
        $tdListMenu .= "<td bgColor=#e7ebef><a href=\"{$urlTemp}\">{$val}</a></td>";
    }
}
$tpl->set( "tdListMenu", $tdListMenu );
$tpl->show( "main" );
$ui->footer();
?>